import pytest
import requests
from config import BASE_URL
from tools import read_json

# 定义类方法
class TestLogin:

    # 前置
    def setup_method(self):
        # 获取验证码
        response = requests.get(BASE_URL + "/api/captchaImage")
        self.uuid = response.json()["uuid"]

    @pytest.mark.parametrize("username, password, code, msg", read_json("login.json"))
    def test_login(self, username, password, code, msg):
        url = BASE_URL + "/api/login"
        data = {
            "username": username,
            "password": password,
            "code": "2",
            "uuid": self.uuid
        }
        response = requests.post(url, json=data)
        print(response.json())
        assert response.status_code == 200
        assert response.json()["code"] == code
        assert msg in response.json()["msg"]
